package server.handler;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import message.*;
import server.session.GroupSession;
import server.session.GroupSessionFactory;
@ChannelHandler.Sharable
public class GroupQuitRequestMessageHandler extends SimpleChannelInboundHandler<GroupQuitRequestMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, GroupQuitRequestMessage groupQuitRequestMessage) throws Exception {
        String groupName = groupQuitRequestMessage.getGroupName();
        GroupSession groupSession = GroupSessionFactory.getGroupSession();
        groupSession.removeMember(groupQuitRequestMessage.getUsername(), groupName);
        channelHandlerContext.writeAndFlush(new GroupQuitResponseMessage(true, "退出成功"));
    }
}
